package com.logicalthinking.socialmall.service.impl;

import com.github.chenlijia1111.utils.common.Result;
import com.github.chenlijia1111.utils.core.PropertyCheckUtil;
import com.github.chenlijia1111.utils.list.Lists;
import com.logicalthinking.socialmall.dao.ThirdPartyUsersMapper;
import com.logicalthinking.socialmall.entity.ThirdPartyUsers;
import com.logicalthinking.socialmall.service.ThirdPartyUsersServiceI;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 第三方登陆用户
 *
 * @author chenLiJia
 * @since 2020-02-18 13:40:25
 **/
@Service
public class ThirdPartyUsersServiceImpl implements ThirdPartyUsersServiceI {


    @Resource
    private ThirdPartyUsersMapper thirdPartyUsersMapper;


    /**
     * 添加
     *
     * @param params 添加参数
     * @return com.github.chenlijia1111.utils.common.Result
     * @author chenLiJia
     * @since 2020-02-18 13:40:25
     **/
    @Override
    public Result add(ThirdPartyUsers params) {

        int i = thirdPartyUsersMapper.insertSelective(params);
        return i > 0 ? Result.success("操作成功") : Result.failure("操作失败");
    }

    /**
     * 编辑
     *
     * @param params 编辑参数
     * @return com.github.chenlijia1111.utils.common.Result
     * @author chenLiJia
     * @since 2020-02-18 13:40:25
     **/
    @Override
    public Result update(ThirdPartyUsers params) {

        int i = thirdPartyUsersMapper.updateByPrimaryKeySelective(params);
        return i > 0 ? Result.success("操作成功") : Result.failure("操作失败");
    }

    /**
     * 根据用户id删除第三方信息
     *
     * @param userId
     * @return
     */
    @Override
    public Result deleteByUserId(Integer userId) {

        List<ThirdPartyUsers> thirdPartyUsers = thirdPartyUsersMapper.select(new ThirdPartyUsers().setClientUserId(userId));
        if (Lists.isNotEmpty(thirdPartyUsers)) {
            for (ThirdPartyUsers thirdPartyUser : thirdPartyUsers) {
                thirdPartyUsersMapper.deleteByPrimaryKey(thirdPartyUser.getId());
            }
        }
        return Result.success("操作成功");
    }

    /**
     * 条件查询
     *
     * @param condition
     * @return
     * @author chenLiJia
     * @since 2020-02-18 13:40:25
     **/
    @Override
    public List<ThirdPartyUsers> listByCondition(ThirdPartyUsers condition) {

        PropertyCheckUtil.transferObjectNotNull(condition, true);
        return thirdPartyUsersMapper.select(condition);
    }


}
